package com.example.mobile2021606127cxz0330;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText edtTxtMainUser;
    private EditText edtTxtMainPsw;
    private Button btnMainLogin;
    private Button btnMainChongzhi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        edtTxtMainUser = (EditText) findViewById(R.id.edtTxt_main_user);
        edtTxtMainPsw = (EditText) findViewById(R.id.edtTxt_main_psw);
        btnMainLogin = (Button) findViewById(R.id.btn_main_login);
        btnMainChongzhi = (Button) findViewById(R.id.btn_main_chongzhi);


//按钮“登录”监听器&点击事件
        btnMainLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user = ((EditText) findViewById(R.id.edtTxt_main_user)).getText().toString().trim();
                String psw = ((EditText) findViewById(R.id.edtTxt_main_psw)).getText().toString().trim();
                if (user.length() == 0 | psw.length() == 0) {
                    Toast.makeText(MainActivity.this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();
                } else if (6 > user.length()) {
                    Toast.makeText(MainActivity.this, "用户名长度应在6-10字之间", Toast.LENGTH_SHORT).show();
                } else if (user.length() > 10) {
                    Toast.makeText(MainActivity.this, "用户名长度应在6-10字之间", Toast.LENGTH_SHORT).show();
                } else if (user.equals("2021606127") & psw.equals("10010")) {
                    Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_LONG).show();
                } else if (user.length() != 0 && psw.length() != 0) {
                    Toast.makeText(MainActivity.this, "账号或密码错误，请重新输入", Toast.LENGTH_SHORT).show();
                }
                Log.e("infor", "获取到的账号为: " + user);
                Log.e("infor", "获取到的密码为: " + psw);
            }
        });


//按钮“重置”监听器&点击事件
        btnMainChongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user = ((EditText) findViewById(R.id.edtTxt_main_user)).getText().toString().trim();
                String psw = ((EditText) findViewById(R.id.edtTxt_main_psw)).getText().toString().trim();
                if (user.length() == 0 | psw.length() == 0) {
                    Toast.makeText(MainActivity.this, "你还没有输入", Toast.LENGTH_SHORT).show();
                } else if (user.length() != 0 & psw.length() != 0) {
                    edtTxtMainUser.setText(null);
                    edtTxtMainPsw.setText(null);
                    Toast.makeText(MainActivity.this, "重置成功", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

}